<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试详情 - 在线考试系统</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --info: #2196f3;
            --light: #f8f9fa;
            --dark: #343a40;
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            min-height: 100vh;
        }

        .navbar {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }

        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }

        .main-content {
            padding: 2rem 0;
        }

        .page-header {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }

        .page-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
        }

        .page-title {
            font-weight: 700;
            margin-bottom: 0.5rem;
            color: var(--dark);
        }

        .page-subtitle {
            color: #6c757d;
            margin-bottom: 0;
        }

        .detail-card {
            background: white;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            overflow: hidden;
        }

        .detail-header {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 1.5rem;
            position: relative;
        }

        .detail-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: rgba(255, 255, 255, 0.3);
        }

        .exam-title {
            font-size: 1.5rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .exam-info {
            display: flex;
            gap: 2rem;
            margin-top: 1rem;
            flex-wrap: wrap;
        }

        .info-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .info-item i {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .detail-body {
            padding: 1.5rem;
        }

        .score-display {
            text-align: center;
            padding: 2rem;
            background: linear-gradient(135deg, #f8f9fa, #e9ecef);
            border-radius: 12px;
            margin-bottom: 2rem;
        }

        .score-number {
            font-size: 4rem;
            font-weight: 700;
            color: var(--primary);
            margin-bottom: 0.5rem;
        }

        .score-label {
            font-size: 1.1rem;
            color: #6c757d;
            margin-bottom: 1rem;
        }

        .score-percentage {
            font-size: 1.5rem;
            font-weight: 600;
            color: var(--dark);
        }

        .score-level {
            display: inline-block;
            padding: 0.5rem 1.5rem;
            border-radius: 25px;
            font-weight: 600;
            margin-top: 1rem;
        }

        .level-excellent {
            background-color: rgba(76, 175, 80, 0.1);
            color: var(--success);
        }

        .level-good {
            background-color: rgba(33, 150, 243, 0.1);
            color: var(--info);
        }

        .level-average {
            background-color: rgba(255, 152, 0, 0.1);
            color: var(--warning);
        }

        .level-poor {
            background-color: rgba(244, 67, 54, 0.1);
            color: var(--danger);
        }

        .comparison-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .comparison-item {
            background: var(--light);
            padding: 1rem;
            border-radius: 8px;
            text-align: center;
        }

        .comparison-label {
            font-size: 0.9rem;
            color: #6c757d;
            margin-bottom: 0.5rem;
        }

        .comparison-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--dark);
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            border: none;
            padding: 0.5rem 1.5rem;
            font-weight: 600;
            border-radius: 8px;
            transition: var(--transition);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
        }

        .back-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 6px;
            text-decoration: none;
            transition: var(--transition);
        }

        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            color: white;
        }

        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 200px;
        }

        .spinner-border {
            color: var(--primary);
        }

        @media (max-width: 768px) {
            .exam-info {
                flex-direction: column;
                gap: 1rem;
            }
            
            .score-number {
                font-size: 3rem;
            }
            
            .comparison-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <a class="navbar-brand" href="/student/home">
            <i class="fas fa-graduation-cap"></i>在线考试系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/exam/list"><i class="fas fa-pen-alt"></i> 考试信息</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/score/analysis"><i class="fas fa-chart-line"></i> 成绩分析</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/resources"><i class="fas fa-book-open"></i> 学习资源</a>
                </li>
            </ul>

            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/student/profile/manage">
                        <i class="fas fa-user-circle"></i> 个人信息
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/logout">
                        <i class="fas fa-sign-out-alt"></i> 退出登录
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="main-content">
    <div class="container">
        <div class="page-header">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1 class="page-title">考试详情</h1>
                    <p class="page-subtitle">查看本次考试的详细成绩信息</p>
                </div>
                <a href="/student/score/analysis" class="back-btn">
                    <i class="fas fa-arrow-left me-2"></i>返回成绩分析
                </a>
            </div>
        </div>

        <div id="examDetailContainer">
            <div class="loading">
                <div class="spinner-border" role="status">
                    <span class="visually-hidden">加载中...</span>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank"><i class="fab fa-github fa-2x"></i></a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        loadExamDetail();
    });
    
    function loadExamDetail() {
        const container = document.getElementById('examDetailContainer');
        const examId = getExamIdFromUrl();
        
        if (!examId) {
            container.innerHTML = '<div class="text-center p-5 text-danger">考试ID无效</div>';
            return;
        }
        
        fetch(`/student/score/api/exam-detail/${examId}`)
            .then(response => response.json())
            .then(data => {
                if (data.success && data.data) {
                    const examDetail = data.data;
                    renderExamDetail(examDetail);
                } else {
                    container.innerHTML = '<div class="text-center p-5 text-danger">考试详情不存在</div>';
                }
            })
            .catch(error => {
                console.error('加载考试详情失败:', error);
                container.innerHTML = '<div class="text-center p-5 text-danger">加载失败</div>';
            });
    }
    
    function getExamIdFromUrl() {
        const pathParts = window.location.pathname.split('/');
        return pathParts[pathParts.length - 1];
    }
    
    function renderExamDetail(examDetail) {
        const container = document.getElementById('examDetailContainer');
        
        const score = examDetail.score || 0;
        const totalScore = examDetail.total_score || 100;
        const percentage = (score / totalScore * 100).toFixed(1);
        const scoreLevel = getScoreLevel(percentage);
        const scoreClass = getScoreClass(percentage);
        
        const html = `
            <div class="detail-card">
                <div class="detail-header">
                    <div class="exam-title">${examDetail.exam_name || '未知考试'}</div>
                    <div class="exam-info">
                        <div class="info-item">
                            <i class="fas fa-book"></i>
                            <span>${examDetail.course_name || '未知课程'}</span>
                        </div>
                        <div class="info-item">
                            <i class="fas fa-calendar"></i>
                            <span>${formatDate(examDetail.submit_time)}</span>
                        </div>
                        <div class="info-item">
                            <i class="fas fa-clock"></i>
                            <span>提交时间</span>
                        </div>
                    </div>
                </div>
                <div class="detail-body">
                    <div class="score-display">
                        <div class="score-number">${score}</div>
                        <div class="score-label">总分: ${totalScore}</div>
                        <div class="score-percentage">${percentage}%</div>
                        <div class="score-level ${scoreClass}">${scoreLevel}</div>
                    </div>
                    
                    <div class="comparison-grid">
                        <div class="comparison-item">
                            <div class="comparison-label">班级排名</div>
                            <div class="comparison-value">${examDetail.class_rank || 'N/A'}</div>
                        </div>
                        <div class="comparison-item">
                            <div class="comparison-label">班级平均分</div>
                            <div class="comparison-value">${(examDetail.class_average || 0).toFixed(1)}</div>
                        </div>
                        <div class="comparison-item">
                            <div class="comparison-label">与平均分差距</div>
                            <div class="comparison-value">${((score - (examDetail.class_average || 0)) || 0).toFixed(1)}</div>
                        </div>
                        <div class="comparison-item">
                            <div class="comparison-label">成绩等级</div>
                            <div class="comparison-value">${scoreLevel}</div>
                        </div>
                    </div>
                    
                    <div class="text-center">
                        <a href="/student/score/analysis" class="btn btn-primary">
                            <i class="fas fa-chart-line me-2"></i>返回成绩分析
                        </a>
                    </div>
                </div>
            </div>
        `;
        
        container.innerHTML = html;
    }
    
    function getScoreLevel(percentage) {
        if (percentage >= 90) return '优秀';
        if (percentage >= 80) return '良好';
        if (percentage >= 70) return '中等';
        if (percentage >= 60) return '及格';
        return '不及格';
    }
    
    function getScoreClass(percentage) {
        if (percentage >= 90) return 'level-excellent';
        if (percentage >= 80) return 'level-good';
        if (percentage >= 70) return 'level-average';
        return 'level-poor';
    }
    
    function formatDate(dateString) {
        if (!dateString) return '未知时间';
        const date = new Date(dateString);
        return date.toLocaleString('zh-CN');
    }
</script>
</body>
</html> 